<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title><?php echo isset($admin_title)?$admin_title:"";?>-<?php echo isset($site_name)?$site_name:"";?></title>
<meta name="author" content="designer:webzhu, date:2012-03-23" />
<link type="image/x-icon" href="<?php echo urldecode(Url::urlFormat("@favicon.ico"));?>" rel="icon">
<link rel="stylesheet" type="text/css" href="<?php echo urldecode(Url::urlFormat("@static/css/base.css"));?>" />
<link rel="stylesheet" type="text/css" href="<?php echo urldecode(Url::urlFormat("@static/css/admin.css"));?>" />
<link rel="stylesheet" type="text/css" href="<?php echo urldecode(Url::urlFormat("@static/css/font_icon.css"));?>" />
<?php echo JS::import('jquery');?>
<script type="text/javascript" src="<?php echo urldecode(Url::urlFormat("@static/js/common.js"));?>"></script>
<!--[if lte IE 7]><script src="<?php echo urldecode(Url::urlFormat("@static/css/fonts/lte-ie7.js"));?>"></script><![endif]-->
</head>
<body >
<div id="header">
	<div class="nav_sub">
			    	您好[<?php echo isset($manager['name'])?$manager['name']:"";?>]&nbsp; | <a href="<?php echo urldecode(Url::urlFormat("/simple/login"));?>" target="_blank">返回前台</a> | <a href="<?php echo urldecode(Url::urlFormat("/admin/logout"));?>">退出</a>&nbsp; | &nbsp; <a id="btn_clear" href="javascript:;">清理缓存</a>
	</div>
    <div id="Logo"><a href=""><img src="<?php echo urldecode(Url::urlFormat("@static/images/logo_min.png"));?>"></a></div>
	<ul id="main_nav" class="clearfix">
	<?php foreach($mainMenu as $key => $item){?>
		<li <?php if($key==$menu_index['menu']){?>class="active"<?php }?>><a href="<?php echo urldecode(Url::urlFormat("$item[link]"));?>"  ><?php echo isset($item['name'])?$item['name']:"";?></a></li>
	<?php }?>
	</ul>
</div>
<div id="mainContent">
	<div id="sidebar" >
		<ul class="menu" style="margin-top:15px;">
		<?php foreach($subMenu as $key => $item){?>
			<li class="submenu">
			<ul><li class="sub-index"><b><a href="javascript:;"><?php echo isset($item['name'])?$item['name']:"";?></a></b></li>
			<?php foreach($menu->getNodes($item['link']) as $key => $item){?>
			<?php if(substr($item['link'],-5)!='_edit' && !$item['hidden'] ){?>
				<li><a href='<?php echo urldecode(Url::urlFormat("$item[link]"));?>' <?php if($item['link']==$nav_link){?>class="current"<?php }?> ><?php echo isset($item['name'])?$item['name']:"";?></a></li>
				<?php }?>
			<?php }?>
			</ul>
			</li>
		<?php }?>
		</ul>
	</div>
	<div id="content" >

		<?php if(!isset($msg)){?><?php $msg=Req::post('msg');?><?php }?>
		<?php if(!isset($validator)){?><?php $validator=Req::post('validator');?><?php }?>
		<?php if(isset($msg[0])){?>
		<div id="message-bar" class="message_<?php echo isset($msg[0])?$msg[0]:"";?>"><?php echo isset($msg[1])?$msg[1]:"";?></div>
		<?php }elseif(isset($validator)){?>
		<div class="message_warning"><?php echo isset($validator['msg'])?$validator['msg']:"";?></div>
		<?php }?>
		<?php echo JS::import('dialog?skin=brief');?>
<?php echo JS::import('dialogtools');?>
<?php echo JS::import('form');?>
<?php echo JS::import('date');?>
<style type="text/css">
    #table_option td{
        width: 8px;
        height: 8px;
        background: #ddd;
        border:1px #999 solid;
        cursor: pointer;
    }
</style>

<h1 class="page_title">
	<?php if(empty($my_ad_obj)){?>添加<?php }else{?>编辑<?php }?>广告
</h1>

<form action="<?php echo urldecode(Url::urlFormat("/app/category_save"));?>" method="post" id="my_ad_form">
	
	<div id="obj_form" class="form2">
	
		<dl class="lineD">
	    <dt>广告名称：</dt>
	    <dd>
	    	<input type="text" id="name" name="name" pattern='required' value="<?php echo isset($my_ad_obj['name'])?$my_ad_obj['name']:"";?>" class="big" alt='广告名称不能为空'>
	    </dd>
	    </dl>
	    
	    <dl class="lineD">
	    <dt>位置：</dt>
	    <dd>
	    	<?php $arr=array('商城首页','购物积分专区','重消积分专区');?>
	    	<select name="sel_type">
	    		<?php if(!empty($my_ad_obj)){?>
	    			<?php foreach($arr as $i => $item){?>
       				<?php if($my_ad_obj['type']==$i){?>
        			<option value='<?php echo isset($i)?$i:"";?>' selected><?php echo isset($arr[$i])?$arr[$i]:"";?></option>
        			<?php }else{?>
        			<option value='<?php echo isset($i)?$i:"";?>'><?php echo isset($arr[$i])?$arr[$i]:"";?></option>
        			<?php }?>
        			<?php }?>
	    		<?php }else{?>
       			<?php foreach($arr as $i => $item){?>
       			
        			<option value='<?php echo isset($i)?$i:"";?>'><?php echo isset($arr[$i])?$arr[$i]:"";?></option>
        		<?php }?>
        		<?php }?>
        		
       		</select>
	    </dd>
	    </dl>
	    
	    <dl class="lineD">
	    <dt>顺序：</dt>
	    <dd>
	    	<input type="text" id="ad_order" name="ad_order" value="<?php echo isset($my_ad_obj['ad_order'])?$my_ad_obj['ad_order']:'0';?>" class="big" >
	    </dd>
	    </dl>
	    
	    
		<dl class="lineD">
	    <dt>类别：</dt>
	    <dd>
	    	<select name="sel_category" id="sel_category" onchange="change_goods()" style="width:368px;">
	    		<option value="0">--请选择类别--</option>
	    	<?php $item=null; $query = new Query("goods_category");$query->where = "parent_id = 0";$items = $query->find(); foreach($items as $key => $item){?>
	    		<option value="<?php echo isset($item[id])?$item[id]:"";?>"><?php echo isset($item['name'])?$item['name']:"";?></option>
	    	<?php }?>
	    	</select>
	    </dd>
	    </dl>
	    
	    <dl class="lineD">
	    <dt>相关商品：</dt>
	    <dd>
	    	<select name="sel_goods" id="sel_goods" style="width:368px;">
	    		<!-- 
	    		<option value="0">--请选择商品--</option>
	    		-->
	    		
	    	</select>&nbsp;
	    	<input type="button" value="添加" id="btn_add"/>
	    </dd>
	    </dl>
	    
	    <dl class="lineD">
	    <dt>目标对象：</dt>
	    <dd>
	    	<select name="sel_mubiao" id="sel_mubiao" multiple='multiple' style="width:368px;height:300px;">
	    		<?php foreach($glist as $key => $it){?>
    				<option value="<?php echo isset($it['id'])?$it['id']:"";?>"><?php echo isset($it['name'])?$it['name']:"";?> -- <?php echo isset($it['sell_price'])?$it['sell_price']:"";?>元</option>
    			<?php }?>
	    	</select>&nbsp;
	    	<ul style="position:absolute;top:100px;left:523px;">
	    		<li><input type="button" value="移除" id="btn_remove"/></li>
	    		<li><input type="button" value="上移" id="btn_pre"/></li>
	    		<li><input type="button" value="下移" id="btn_next"/></li>
	    	</ul>
	    </dd>
	    </dl>
	    
	    <div style="text-align:center">
	    	<input type="hidden" name="hid_sel_str" id="hid_sel_str"/>
	    	<?php if(!empty($my_ad_obj)){?>
	    	<input type="hidden" name="id" value="<?php echo isset($my_ad_obj['id'])?$my_ad_obj['id']:"";?>"/>
	    	<?php }?>
	    	<input id="btn_submit" type="button" value="提交" class="button">&nbsp;&nbsp;&nbsp;&nbsp;<input type="reset" value="重置" class="button">
	    </div>
	</div>

</form>


<script type="text/javascript">

$(function(){
	
	$("#sel_category").change(function(){
		var category_id = $("#sel_category").val();
		$("#sel_goods option:gt(0)").remove();
		$.post("<?php echo urldecode(Url::urlFormat("/app/getGoodsListByClassifyId"));?>",{category_id :category_id },function(data){
			
			
			var str = '', i;
			if(data.length<1)
			{
				//$("#sel_goods").html("<option value='0'>--请选择商品--</option>");
				$("#sel_goods").html("");
			}
			else
			{
				$("#sel_goods").html("");
				for(i=0,c=data.length; i<c; i++)
				{
					str += "<option value='"+data[i]['id']+"'>"+data[i]['name']+" -- "+data[i]['sell_price']+"元</option>";
				}
				$("#sel_goods").append( str );
			}
			
			
		},'json');
	});
	
	
	//添加元素
	$("#btn_add").click(function(){
		var selected_item = $("#sel_goods").find("option:selected");
		if(selected_item.length > 0)
		{
			var v = selected_item.val();
			var is_flag = true;
			$("#sel_mubiao").find("option").each(function(){
				if($(this).val() == v)
				{
					is_flag = false;
					alert('该商品已存在于目标对象中，请不要重复操作');
					return false;;
				}
			});
			if( is_flag )
			{
				selected_item.clone().appendTo("#sel_mubiao");	
			}
		}
	});
	
	//向上移动元素
	$("#btn_remove").click(function(){
		$("#sel_mubiao").find("option:selected").remove();
	});
	
	//向上移动元素
	$("#btn_pre").click(function(){
		//获取选中项
		var selected_item = $("#sel_mubiao option:selected");
		//插入到选中项前一个option元素之前
		selected_item.insertBefore(selected_item.prev('option'))
	});
	
	//向下移动元素
	$("#btn_next").click(function(){
		//获取选中项
		var selected_item = $("#sel_mubiao option:selected");
		//插入到选中项后一个option元素之后
		selected_item.insertAfter(selected_item.next('option'))
	});
	
	
	$("#btn_submit").click(function(){
		var name = $("#name").val();
		if(name == '')
		{
			alert('广告名称不能为空');
			return;
		}
		var ad_order = $("#ad_order").val();
		if(isNaN(ad_order) || ad_order=='')
		{
			alert('顺序不能为空且必须是数字');
			return;
		}
		
		var sel_mubiao = $("#sel_mubiao").find("option");
		
		if(sel_mubiao.length <= 0)
		{
			alert('请选择商品添加到目标对象');
			return;
		}
		var str = '';
		$("#sel_mubiao").find("option").each(function(){
			str += ($(this).attr('value')+",");
		});
		str = str.substring(0,str.length-1);
		$("#hid_sel_str").val(str);
		
		$("#my_ad_form").submit();
		
	});
});

/*
function check()
{
	var sel_category = $("#sel_category").val();
	var sel_seller = $("#sel_goods").val();
	if(sel_category == 0)
	{
		alert('请选择类别');
		return false;
	}
	
	if(sel_seller == 0)
	{
		alert('请选择商品');
		return false;
	}
}
*/






$("#table_option td:eq(<?php echo isset($contents[0]['position'])?$contents[0]['position']:"";?>)").css("background","#000");
</script>
	</div>
</div>
<script type="text/javascript">
	$(function () {
		if('<?php echo Req::args("con");?>'=='admin'){
			$(".submenu .current").parent().parent().parent().addClass('current');
		}else{
			$(".submenu").addClass('current');
		}
		$(".submenu .sub-index").on("click",function(){
			$(this).parent().parent().toggleClass('current');
		})
	})

</script>
</body>
</html>
<script>
	$("#btn_clear").on("click",function(){
		$.post("<?php echo urldecode(Url::urlFormat("/admin/clear_act"));?>",function(data){
			art.dialog.tips("<p class='"+data['status']+"'>"+data['msg']+"</p>");
		},'json');
	});
</script>
<!--Powered by TinyRise-->